package com.gfxy.modules.items.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gfxy.modules.items.entity.InnovationAndEntrepreneurship;
import com.gfxy.modules.items.entity.teachingresult.TeachingResultContent;
import com.gfxy.modules.items.mapper.InnovationAndEntrepreneurshipMapper;
import com.gfxy.modules.items.service.IInnovationAndEntrepreneurshipService;
import com.gfxy.modules.items.vo.*;
import com.gfxy.modules.excel.ExcelUtil;
import org.apache.poi.ss.usermodel.Row;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description: 创新创业大赛
 * @Author: jeecg-boot
 * @Date:   2021-06-29
 * @Version: V1.0
 */
@Service
public class InnovationAndEntrepreneurshipServiceImpl extends AbstractProjectServiceImpl<InnovationAndEntrepreneurshipMapper, InnovationAndEntrepreneurship> implements IInnovationAndEntrepreneurshipService {
	protected int memberCellNum = 5;


	private Integer translateMatchClassess(String name) {
		if (name == null || name.equals("")) {
			return 0;
		} else if (name.equals("国赛")) {
			return 1;
		} else if (name.equals("省赛")) {
			return 2;
		} else {
			return 0;
		}
	}

	private Integer translateMatchGroup(String name) {
		if (name == null || name.equals("")) {
			return 0;
		} else if (name.equals("创意组")) {
			return 1;
		} else if (name.equals("创业组")) {
			return 2;
		} else if (name.equals("公益组")) {
			return 3;
		} else {
			return 0;
		}
	}

	private Integer translateAward(String name) {
		if (name == null || name.equals("")) {
			return 0;
		} else if (name.equals("金奖")) {
			return 1;
		} else if (name.equals("银奖")) {
			return 2;
		} else if (name.equals("铜奖")) {
			return 3;
		} else {
			return 0;
		}
	}

	@Override
	protected void pass(String id, String isPass) {

	}

	@Override
	protected InnovationAndEntrepreneurship getOneProject(Row row) {
		String date = ExcelUtil.formatCell(row.getCell(0));

		String projectName = ExcelUtil.formatCell(row.getCell(1));
		String classess = ExcelUtil.formatCell(row.getCell(2));
		String Group = ExcelUtil.formatCell(row.getCell(3));
		String award = ExcelUtil.formatCell(row.getCell(4));

		InnovationAndEntrepreneurship zxjpk = new InnovationAndEntrepreneurship();

		zxjpk.setDate(date);
		zxjpk.setAward(translateAward(award));
		zxjpk.setMatchClassess(translateMatchClassess(classess));
		zxjpk.setMatchGroup(translateMatchGroup(Group));

		zxjpk.setProjectName(projectName);

		zxjpk.setIsPass(0);
		zxjpk.setTotalScore(this.getTotalScore(zxjpk));
		return zxjpk;
	}
	@Override
	protected String[] getMemberArray(Row row) {
		String nameStrs = ExcelUtil.formatCell(row.getCell(memberCellNum));
		return nameStrs.split(memberNameSeparator);
	}
	@Override
	public Double getTotalScore(InnovationAndEntrepreneurship innovationAndEntrepreneurship) {
		Integer award = innovationAndEntrepreneurship.getAward();
		int matchClassess = innovationAndEntrepreneurship.getMatchClassess();
		double result = 0.0;
		if (matchClassess == 1) {
			if (award == 1) {
				result = 240;
			} else if (award == 2) {
				result = 180;
			} else if (award == 3) {
				result = 70;
			}
		} else if (matchClassess == 2) {
			if (award == 1) {
				result = 60;
			} else if (award == 2) {
				result = 40;
			} else if (award == 3) {
				result = 25;
			}
		}
		return result;
//	}
	}

	@Override
	public IPage<InnovationAndEntrepreneurshipMemberPage> getZxjpkMemberPageListByYear(String date, Integer pageNo, Integer pageSize) {
		Page<InnovationAndEntrepreneurshipMemberPage> pagePage = new Page<>(pageNo, pageSize);
		return pagePage.setRecords(this.baseMapper.innovationAndEntrepreneurListByYear(date));

	}
	@Override
	public List<InnovationAndEntrepreneurshipMemberPage> getZxjpkMemberPageListByYear(String date) { ;
		return this.baseMapper.innovationAndEntrepreneurListByYear(date);
	}

//	@Override
//	public Double[] getMemberListScore(double totalScore, int memberNum) {
//		return new Double[0];
//	}


//	@Override
//	public double getTotalScore(Integer matchClassess, Integer award) {

	@Override
	protected List<TeachingResultContent> createTeachingResultContent(InnovationAndEntrepreneurship qnjsjkbs)  {

		List<TeachingResultContent> result = new ArrayList<>();

		// 类型
		TeachingResultContent classTeachingResultContent = new TeachingResultContent();
		classTeachingResultContent.setType(1);
		classTeachingResultContent.setLevel(qnjsjkbs.getMatchClassess());

		try {
			classTeachingResultContent.setValue(dictTranslater.getDictValue(InnovationAndEntrepreneurship.class, "matchClassess", String.valueOf(qnjsjkbs.getMatchClassess())));
			result.add(classTeachingResultContent);
		} catch (NoSuchFieldException e) {
			log.error(e.getMessage(),e);
		}

		//奖项
		TeachingResultContent awardTeachingResultContent = new TeachingResultContent();
		awardTeachingResultContent.setType(1);
		awardTeachingResultContent.setLevel(qnjsjkbs.getAward());
		try {
			awardTeachingResultContent.setValue(dictTranslater.getDictValue(InnovationAndEntrepreneurship.class, "matchGroup", String.valueOf(qnjsjkbs.getAward())));
			result.add(awardTeachingResultContent);
		} catch (NoSuchFieldException e) {
			log.error(e.getMessage(),e);
		}

		//奖项
		TeachingResultContent groupTeachingResultContent = new TeachingResultContent();
		awardTeachingResultContent.setType(1);
		awardTeachingResultContent.setLevel(qnjsjkbs.getMatchGroup());
		try {
			awardTeachingResultContent.setValue(dictTranslater.getDictValue(InnovationAndEntrepreneurship.class, "award", String.valueOf(qnjsjkbs.getMatchGroup())));
			result.add(awardTeachingResultContent);
		} catch (NoSuchFieldException e) {
			log.error(e.getMessage(),e);
		}

		return result;
	}


}
